﻿using System;
using System.Windows.Forms;
using Database;
using KPP.Properties;

namespace KPP
{
    public partial class PassInformation : Form
    {
        private readonly bool _block;

        public PassInformation(Pass pass, bool block)
        {
            InitializeComponent();

            passIdTextBox.Text = pass.Number;
            passTypeTextBox.Text = pass.GetPassType();
            passGetDateTimePicker.Text = pass.GetIssueDate();
            dormTextBox.Text = pass.GetDorm();

            _block = block;
            BlockButton.Text = block ? "Заблокировать" : "Разблокировать";
        }

        private void BlockButton_Click(object sender, EventArgs e)
        {
            if (_block)
            {
                DatabaseHelper.BlockPass(passIdTextBox.Text);
                MessageBox.Show(Resources.Success, Resources.Result, MessageBoxButtons.OK);
                Close();
            }
            else
            {
                DatabaseHelper.UnblockPass(passIdTextBox.Text);
                MessageBox.Show(Resources.Success, Resources.Result, MessageBoxButtons.OK);
                Close();
            }
        }

        private void OkButton_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
